package com.rr.middle;

import com.rr.entity.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhuangcanrun
 * @Date 2022/06/27/19:53
 * @description
 **/

/*
* https://leetcode.cn/problems/find-largest-value-in-each-tree-row/
* */
public class LargestValues {
    public List<Integer> largestValues(TreeNode root) {
        List<Integer> ans = new ArrayList<>();
        fullAns(root, ans, 0);
        return ans;
    }

    private void fullAns(TreeNode root,List<Integer> ans,int index) {
        if (root == null) {
            return;
        }
        if (ans.size() == index) {
            ans.add(Integer.MIN_VALUE);
        }
        Integer integer = ans.get(index);
        if (integer < root.val) {
            ans.remove(index);
            ans.add(index, root.val);
        }
        fullAns(root.left, ans, index + 1);
        fullAns(root.right, ans, index + 1);
    }
}
